<?php

namespace app\api\controller\v1\train;

use app\Request;

class TrainController
{
    public function index(Request $request)
    {
        list( $page) = $request->getMore([
            ['page', 1 , 'intval'] ,
        ], true);
        $where[] = ['status' , '=' , 1] ;
        $where[] = ['appoint_staff_id' , '=' , $request->staffId()] ;
        $list = \app\model\train\Train::where($where)->page($page , 10)->order('id desc')->select() ;

        return app('json')->success([
            'list' =>  $list ,
        ]);
    }
    public function detail(Request  $request){
        list( $id) = $request->getMore([
            ['id', 0 , 'intval'] ,
        ], true);
        $where[] = ['id' , '=' , $id] ;
        $where[] = ['appoint_staff_id' , '=' , $request->staffId()] ;
        $info = \app\model\train\Train::where($where)->find() ;
        $info['img_urls'] = $info['img_urls'] != '' ? explode(',' , $info['img_urls']) : [];
        return app('json')->success([
            'info' =>  $info ,
        ]);
    }
    public function submit(Request $request)
    {
        list( $id , $imgUrls , $remark ) = $request->getMore([
            ['id', 0] ,
            ['img_urls', ''] ,
            ['remark', ''] ,
        ], true);
        $where[] = ['id' , '=' , $id] ;
        $info = \app\model\train\Train::where($where)->find() ;
        $info->img_urls = $imgUrls ;
        $info->remark = $remark ;
        $info->submit_status = 9 ;
        $info->submit_time = time() ;

        $info->save() ;
        return app('json')->success('提交成功' );
    }
}